
/*
  开启node服务
  使用koa服务
  初始化中间件
  端口设置
*/
const koa = require("koa");
const R = require("ramda");

//大脑自动将信息归到金字塔不同分组中，以便于理解
// 此文件起动服务，路由服务，数据库服务，中间件服务
// 时间顺序
// app.use(async ctx => {
//     ctx.body = 'Hello World';
//   });

// app.listen(3000);
const { resolve } = require("path");
const r = path => resolve(__dirname, path);
// const MIDDLEWARES = ["database", "common", "router"];
const MIDDLEWARES = ["database","router"];

class Server {
  constructor() {
    this.app = new koa();
    this.useMiddleWares(this.app)(MIDDLEWARES);
  }
  useMiddleWares(app) {
    return R.map(
      R.compose(i => i(app), require, i => r(`./middlewares/${i}`))
    );
  }
  start() {
    this.app.listen(3006, () => {
      console.log("起动node服务");
    });
  }
}

const app = new Server();
app.start();
